#ifndef ROBOTIC_OPENGL_H
#define ROBOTIC_OPENGL_H

#include <QOpenGLWidget>
#include <QOpenGLExtraFunctions>
#include <QVector>
#include <QStringList>
#include <QOpenGLShaderProgram>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QTimer>
#include <QTime>
#include <QMatrix4x4>
#include <QMatrix3x3>
#include <QQuaternion>
#include <QVector2D>

class RoboticOpenGLView : public QOpenGLWidget,public QOpenGLExtraFunctions{
    Q_OBJECT

public:
    RoboticOpenGLView(QWidget *parent = nullptr);
    ~RoboticOpenGLView();
private:
    bool           loaddone;
    short          looprundelay;

    QVector<float> vertices_Base;
    QVector<float> vertices_Joint1;
    QVector<float> vertices_Joint2;
    QVector<float> vertices_Joint3;
    QVector<float> vertices_Joint4;
    QVector<float> vertices_Joint5;
    QVector<float> vertices_Joint6;
    QVector<float> vertices_Tool;


    QVector<float> Position;
    QVector<float> Normal;
    QOpenGLShaderProgram shaderprogram;

    QOpenGLVertexArrayObject VAO;

    QOpenGLBuffer VBO_Base;
    QOpenGLBuffer VBO_Joint1;
    QOpenGLBuffer VBO_Joint2;
    QOpenGLBuffer VBO_Joint3;
    QOpenGLBuffer VBO_Joint4;
    QOpenGLBuffer VBO_Joint5;
    QOpenGLBuffer VBO_Joint6;
    QOpenGLBuffer VBO_Tool;

    QMatrix4x4 model;
    QMatrix4x4 view;
    QMatrix4x4 projection;

    GLfloat xtrans;
    GLfloat ytrans;
    GLfloat ztrans;

    QVector2D mousePos;
    QQuaternion rotation;

    float RobotJointPos[6];
protected:
    virtual void initializeGL() override;
    virtual void paintGL() override;
    virtual void resizeGL(int w,int h) override;

    QVector<float> loadAscllStl(QString filename, float ratio);

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

public:
    void RoboticOpenViewUpdate();
    void RoboticOpenViewUpdate(double JointPos[6]);
};
#endif // ROBOTIC_OPENGL_H

